import { useState, useCallback } from 'react';
import { randomString } from '@/utils/utils';
import { login } from '@/api';
export default function useLogin() {
  const [captchaImg, setCaptchaImg] = useState<string>('');
  const [checkKey, setCheckKey] = useState<string>('');
  const getCaptchaImg = useCallback(async () => {
    const randomstr = randomString(16);
    setCheckKey(randomstr);
    const result: any = await login.getCaptchaImage(
      {
        isPass: true,
      },
      randomstr,
    );
    if (result && result.result) {
      setCaptchaImg(result.result);
    }
  }, []);

  return {
    captchaImg,
    checkKey,
    getCaptchaImg,
  };
}
